package com.google.jgib.util.irc;

import org.jibble.pircbot.*;

import com.google.code.jgib.growl.requests.GntpNotificationRequest;
import com.google.code.jgib.growl.requests.GntpNotificationRequest.NotificationType;

public class IrcBot extends PircBot{

	private String hostName = "localhost";
	private int portNum = 23053;
	
	public IrcBot(String name, String host, int port){
		hostName = host;
		portNum = port;
		this.setName(name);
		this.setLogin("JGIb");
	}


	public void onMessage(String channel, String sender,
			String login, String hostname, String message) {
		GntpNotificationRequest not = new GntpNotificationRequest();
		if (message.equalsIgnoreCase("!pokewarg")) {
			not.doNotify("localhost", 23053, NotificationType.NEWMSG, "Poked in "+channel+"!");
			this.sendMessage(channel, "Poked Warg for you!");
		}
	}
	@Override
	protected void onPrivateMessage(String sender, String login, String hostname, String message){
		GntpNotificationRequest not = new GntpNotificationRequest();
		if(message.equalsIgnoreCase("!notifywarg")){
			not.doNotify("localhost", 23053, NotificationType.NEWMSG, "Poked by "+sender+"!");
			this.sendMessage(sender, "Notified Warg for you!");
		}		
	}
	@Override
	protected void onConnect(){
		GntpNotificationRequest notification = new GntpNotificationRequest();
		notification.doNotify("localhost", 23053, NotificationType.CONNECT, "Connected to "+this.getServer()+".");
	}
	protected void onPart(String channel,
            String sender,
            String login,
            String hostname){
		
		
		GntpNotificationRequest notification = new GntpNotificationRequest();
		notification.doNotify("localhost", 23053, NotificationType.USERPART, "User "+sender+" parted from "+channel+".");
		
	}
	
	protected void onJoin(String channel,
            String sender,
            String login,
            String hostname){
		
		
		GntpNotificationRequest notification = new GntpNotificationRequest();
		notification.doNotify("localhost", 23053, NotificationType.USERJOIN, "User "+sender+" joined "+channel+".");
		
	}
	
	protected void onDisconnect(){
		GntpNotificationRequest notification = new GntpNotificationRequest();
		notification.doNotify("localhost", 23053, NotificationType.DISCONNECT, "Disconnected from "+this.getServer()+"!\nWaiting 15 sec before reconnection attempt!");

	}
	
}